#20202321 邬昱初
#日期：20210524
import socket
import os
import base64
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 8010))
ser = input("please enter file to transfer：")
s.sendall(ser.encode())
os.chdir(r"E:\mo")
file = open(ser, 'a+')
text = file.read()
text = text.encode('utf-8')
encode_text = base64.b32encode(text)
s.sendall(encode_text)
file.close()
data = s.recv(1024)
print("come from ('127.0.0.1') message：", data.decode())
s.sendall("receive".encode())
name = s.recv(1024)
print("come from ('127.0.0.1') message：", name.decode())
data = s.recv(1024)
f = open("reply.txt", "w")
f.write(data.decode())
f.close()
print("file has sent out.")
s.sendall("receive".encode())
s.close()